<?php
	header( "Content-Type: text/html");
	include("mysql_connect.php");
	
	$strKeyWord = $_POST['SelectKey'];
	
	$strHref =  $_POST['Href'];
	
	$strSqlCommand = "SELECT FirstName, LastName , AgentID FROM REAgent";
	
	if(strlen($strKeyWord) > 0)
		$strSqlCommand .= " WHERE FirstName LIKE '%".$strKeyWord."%' OR LastName LIKE '%".$strKeyWord."%'";
	
	$strSqlCommand .= " ORDER BY LastName LIMIT 0, 30";
	
	$result = mysql_query($strSqlCommand);

	//$ArrayAgent = array("Kevin Adams","Amelia Ahne","Sabastion Battaglia","Harold Cannily");
	
//	echo '<li data-role="list-divider" role="heading">A</li>';
	//foreach($ArrayAgent as $strName)
	$Divider = "0";
	$nIdx = 0;
	$nRowNum = @mysql_num_rows($result);
	$getRec=array();
	while($rowMedia = @mysql_fetch_row($result))	
	{
		$getRec[]=$rowMedia;
	}
	for($i=0;$i<count($getRec);$i++)	
	{
		$rowMedia=$getRec[$i];
		$nIdx++;
		if(strncmp( $rowMedia[1], $Divider, 1) != 0)
		{
			echo '<div data-role="collapsible-set" data-theme="b" data-content-theme="">';
			echo '<div data-role="collapsible" data-collapsed="false">';		
/*	daria_delete
			if(strcmp($Divider,"0")==0)
			{
				echo '<li class="ui-li ui-li-divider ui-bar-b ui-corner-top" data-role="list-divider" role="heading" data-theme="b" data-inset="true">';
			}
			else
			{
				echo '<li class="ui-li ui-li-divider ui-bar-b" data-role="list-divider" role="heading" data-theme="b" data-inset="true">';
			}*/
			$Divider = substr($rowMedia[1],0,1);
			
			echo '<h3>';		
			echo $Divider;
			echo '</h3>';		
		}
		echo '<a data-role="button" data-transition="fade" href="#page13" id="'.$rowMedia[2].'" class="AgentSelect">';
		
/*	daria_delete
	if( $strHref == "Page7ToPage4" )
		{
			echo '<a class="ui-link-inherit AgentSelect" href="#page7" data-transition="slide" id="'.$rowMedia[2].'">';
		}
		else
		{
			echo '<a class="ui-link-inherit AgentSelect" href="#page6" data-transition="slide" id="'.$rowMedia[2].'">';
		}
*/
		echo $rowMedia[0].' '.$rowMedia[1];		
		echo '</a>';

		$chkFooter='n';
		if(isset($getRec[$i+1])){
			if(strncmp( $getRec[$i+1][1], $Divider, 1) != 0)
			{
				$chkFooter='y';
			}
		}else{
			$chkFooter='y';
		}
		if($chkFooter=='y'){
			echo '</div></div>';		
		}
	}
	
?>
